/**
 * File Info：com.mys.springboot.controller.user.UserController.java
 * Created Date：2017年5月15日 下午2:53:34
 * Created User: mys
 */
package com.mys.springboot.controller.user;

import com.mys.springboot.config.base.BaseController;
import com.mys.springboot.config.base.BaseResult;
import com.mys.springboot.config.cache.redis.RedisUtils;
import com.mys.springboot.model.User;
import com.mys.springboot.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @description
 * 
 * @author mys
 * @version 1.0
 *
 */
@Controller
@RequestMapping("/user")
public class UserController extends BaseController {
	@Resource
	private UserService userService;
	@Autowired
	private RedisUtils redisUtils;



	@RequestMapping("/add/{name}/{age}")
	public @ResponseBody BaseResult addUser(@PathVariable("name") String name, @PathVariable("age") Integer age) {
		User user = new User();
		user.setName(name);
		user.setAge(age);
		try {
			userService.addUser(user);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BaseResult.success();
	}

	@RequestMapping("/queryAll")
	public @ResponseBody BaseResult queryAll()
	{
		redisUtils.set("123", "hello world");
		System.out.println("进入了方法");
		String string= redisUtils.get("123").toString();
		return BaseResult.success().setData(userService.findAll()+string);
	}

	@RequestMapping("/delete/{id}")
	public @ResponseBody BaseResult delete(@PathVariable("id") Long id) {
		userService.delete(id);
		return BaseResult.success();
	}

	@RequestMapping("/deleteUser/{id}")
	public @ResponseBody BaseResult deleteUser(@PathVariable("id") Long id) {
		User user = userService.findOne(id);
		userService.delete(user);
		return BaseResult.success();
	}

	@RequestMapping("/findByName/{name}")
	public @ResponseBody BaseResult findByName(@PathVariable("name") String name) {
		return BaseResult.success().setData(userService.findByName(name));
	}
//
//	@RequestMapping("/findUser/{name}")
//	public @ResponseBody BaseResult findUser(@PathVariable("name") String name) {
//		return BaseResult.success().setData(userService.findUser(name));
//	}
}
